package com.dpiinc.TechPage.pen.dialog;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.dpiinc.TechPage.R;

import org.jetbrains.annotations.Nullable;

/**
 * Created by hu489_000 on 2018-07-23.
 */

public class OneButtonDialog extends BaseFloatDialog {

    private static OneButtonDialog mOneButtonDialog;

    private Context mContext;

    public OneButtonDialog(@Nullable Context context) {
        super(context);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.dialog_base_tip_layout);
    }

    public static void ShowDialog(@Nullable Context context, String title, String content, boolean isOneButton, View.OnClickListener OkClickListener){
        mOneButtonDialog = new OneButtonDialog(context);
        mOneButtonDialog.show();
        TextView btnOK = (TextView)mOneButtonDialog.findViewById(R.id.btn_ok);
        btnOK.setOnClickListener(OkClickListener);
        TextView btn_cancel = (TextView)mOneButtonDialog.findViewById(R.id.btn_cancel);
        TextView dialog_title = (TextView)mOneButtonDialog.findViewById(R.id.dialog_title);
        if(!TextUtils.isEmpty(title)){
            dialog_title.setText(title);
        }
        TextView dialog_content = (TextView)mOneButtonDialog.findViewById(R.id.dialog_content);
        if(!TextUtils.isEmpty(content)){
            dialog_content.setText(content);
        }
        if(isOneButton){
            btn_cancel.setVisibility(View.GONE);
        }else{
            btn_cancel.setVisibility(View.VISIBLE);
            btn_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dismissDialog();
                }
            });
        }

        if(OkClickListener == null ){
            btnOK.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dismissDialog();
                }
            });
        }
    }

    public static void dismissDialog(){

        if(mOneButtonDialog!= null && mOneButtonDialog.isShowing()){
            mOneButtonDialog.dismiss();
        }

    }
}
